package cn.silver.module.configuration.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.silver.framework.excel.utils.ExcelUtil;
import cn.silver.framework.log.annotation.Log;
import cn.silver.framework.log.enums.OperateEnums;
import cn.silver.framework.mybatis.controller.BusController;
import cn.silver.module.configuration.bean.DictItemBean;
import cn.silver.module.configuration.domain.SysDictItem;
import cn.silver.module.configuration.param.DictItemParam;
import cn.silver.module.configuration.service.ISysDictItemService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 数据字典信息
 *
 * @author Silver Zhou
 */
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/config/dict/item")
@Tag(name = "配置管理-字典管理-字典数据管理")
public class SysDictItemController extends BusController<ISysDictItemService, SysDictItem, DictItemParam, DictItemBean> {

    @Override
    @Resource
    public void setBaseService(ISysDictItemService baseService) {
        this.setCode("config:dict");
        this.baseService = baseService;
        this.setTitle("配置管理-字典管理-字典数据管理");
    }

    /**
     * 导出字典数据列表
     */
    @Log(title = "字典数据", operate = OperateEnums.OSS_EXPORT)
    @SaCheckPermission("system:dict:export")
    @PostMapping("/export")
    public void export(DictItemParam dictData, HttpServletResponse response) {
        List<DictItemBean> list = baseService.selectList(dictData);
        ExcelUtil.exportExcel(list, "字典数据", DictItemBean.class, response);
    }


//    /**
//     * 根据字典类型查询字典数据信息
//     *
//     * @param dictType 字典类型
//     */
//    @GetMapping(value = "/type/{dictType}")
//    public Result<List<SysDictDataVo>> dictType(@PathVariable String dictType) {
//        List<SysDictDataVo> data = dictTypeService.selectDictDataByType(dictType);
//        if (ObjectUtil.isNull(data)) {
//            data = new ArrayList<>();
//        }
//        return Result.ok(data);
//    }

}
